﻿using Gasgoo.ShareLibrary.Framework.Global;
using Gasgoo.ShareLibrary.Framework.iCacheProvider;
using Gasgoo.ShareLibrary.Framework.ServiceDefine;
using Orleans.Providers;
using System.Threading.Tasks;

namespace Gasgoo.CacheProvider
{
    [StorageProvider(ProviderName = Constants.CACHE_SQLSERVE_PROVIDER)]
    public class KeyValueProvider : GasgooServiceBase<string>, IKeyValueProvider
    {
        public Task<string> GetAsync()
        {
            return Task.FromResult(this.State);
        }

        public async Task RemoveAsync()
        {
            await this.ClearStateAsync();
            this.DeactivateOnIdle();
        }

        public async Task SetAsync(string payload)
        {
            this.State = payload;
            await this.WriteStateAsync();
        }
    }
}
